﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.d90_ybb_glzxMenu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void d90_ybb_glzx_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            d90_ybb_glzxMgr mgr = new d90_ybb_glzxMgr();
            e.Total = int.Parse(mgr.GetRecordCount_d90_ybb_glzx(e.Parameters[d90_ybb_glzx_Filter.ParamPrefix]));
            IList<d90_ybb_glzx> list = mgr.FindAllByPage_d90_ybb_glzx(e.Start.ToString(), e.Limit.ToString(), e.Parameters[d90_ybb_glzx_Filter.ParamPrefix]);
            d90_ybb_glzx_MainStore.DataSource = list;
            d90_ybb_glzx_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            d90_ybb_glzxMgr mgr = new d90_ybb_glzxMgr();
            RowSelectionModel sm = d90_ybb_glzx_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                d90_ybb_glzx _d90_ybb_glzx = new d90_ybb_glzx();
                _d90_ybb_glzx.yf = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_d90_ybb_glzx(_d90_ybb_glzx))
                {
                    log.Debug("d90_ybb_glzx中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            d90_ybb_glzx_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            d90_ybb_glzxMgr mgr = new d90_ybb_glzxMgr();
            d90_ybb_glzx _d90_ybb_glzx = new d90_ybb_glzx();
            if (Hid.Text.Length > 0)
                _d90_ybb_glzx = mgr.FindById_d90_ybb_glzx(int.Parse(Hid.Text));
            
			_d90_ybb_glzx.dzbm = Txtdzbm.Text.Trim();
			_d90_ybb_glzx.dzmc = Txtdzmc.Text.Trim();
			_d90_ybb_glzx.dqbm = Txtdqbm.Text.Trim();
			_d90_ybb_glzx.djbz = Txtdjbz.Text.Trim();
			_d90_ybb_glzx.jsbz = Txtjsbz.Text.Trim();
			_d90_ybb_glzx.rchj = Txtrchj.Text.Trim();
			_d90_ybb_glzx.sjrc = Txtsjrc.Text.Trim();
			_d90_ybb_glzx.ejrc = Txtejrc.Text.Trim();
			_d90_ybb_glzx.yjrc = Txtyjrc.Text.Trim();
			_d90_ybb_glzx.fyhj = Txtfyhj.Text.Trim();
			_d90_ybb_glzx.sjhj = Txtsjhj.Text.Trim();
			_d90_ybb_glzx.ejhj = Txtejhj.Text.Trim();
			_d90_ybb_glzx.yjhj = Txtyjhj.Text.Trim();
			_d90_ybb_glzx.bchj = Txtbchj.Text.Trim();
			_d90_ybb_glzx.sjbchj = Txtsjbchj.Text.Trim();
			_d90_ybb_glzx.ejbchj = Txtejbchj.Text.Trim();
			_d90_ybb_glzx.yjbchj = Txtyjbchj.Text.Trim();
			_d90_ybb_glzx.fmrc = Txtfmrc.Text.Trim();
			_d90_ybb_glzx.fmfy = Txtfmfy.Text.Trim();
			_d90_ybb_glzx.fmbc = Txtfmbc.Text.Trim();
			_d90_ybb_glzx.dbrc = Txtdbrc.Text.Trim();
			_d90_ybb_glzx.dbfy = Txtdbfy.Text.Trim();
			_d90_ybb_glzx.dbbc = Txtdbbc.Text.Trim();
			_d90_ybb_glzx.qtrc = Txtqtrc.Text.Trim();
			_d90_ybb_glzx.qtfy = Txtqtfy.Text.Trim();
			_d90_ybb_glzx.qtbc = Txtqtbc.Text.Trim();
			_d90_ybb_glzx.tjrc = Txttjrc.Text.Trim();
			_d90_ybb_glzx.tjbc = Txttjbc.Text.Trim();
			_d90_ybb_glzx.mzrc = Txtmzrc.Text.Trim();
			_d90_ybb_glzx.mzbc = Txtmzbc.Text.Trim();
			_d90_ybb_glzx.mzsjrc = Txtmzsjrc.Text.Trim();
			_d90_ybb_glzx.mzejrc = Txtmzejrc.Text.Trim();
			_d90_ybb_glzx.mzyjrc = Txtmzyjrc.Text.Trim();
			_d90_ybb_glzx.mzljrc = Txtmzljrc.Text.Trim();
			_d90_ybb_glzx.mzsjfy = Txtmzsjfy.Text.Trim();
			_d90_ybb_glzx.mzejfy = Txtmzejfy.Text.Trim();
			_d90_ybb_glzx.mzyjfy = Txtmzyjfy.Text.Trim();
			_d90_ybb_glzx.mzljfy = Txtmzljfy.Text.Trim();
			_d90_ybb_glzx.mzsjbc = Txtmzsjbc.Text.Trim();
			_d90_ybb_glzx.mzejbc = Txtmzejbc.Text.Trim();
			_d90_ybb_glzx.mzyjbc = Txtmzyjbc.Text.Trim();
			_d90_ybb_glzx.mzljbc = Txtmzljbc.Text.Trim();
			_d90_ybb_glzx.mbrc = Txtmbrc.Text.Trim();
			_d90_ybb_glzx.mbfy = Txtmbfy.Text.Trim();
			_d90_ybb_glzx.mbbc = Txtmbbc.Text.Trim();
			_d90_ybb_glzx.mztqrc = Txtmztqrc.Text.Trim();
			_d90_ybb_glzx.mztqfy = Txtmztqfy.Text.Trim();
			_d90_ybb_glzx.mztqbc = Txtmztqbc.Text.Trim();
			_d90_ybb_glzx.ffmrc = Txtffmrc.Text.Trim();
			_d90_ybb_glzx.ffmfy = Txtffmfy.Text.Trim();
			_d90_ybb_glzx.ffmbc = Txtffmbc.Text.Trim();
			_d90_ybb_glzx.sfmrc = Txtsfmrc.Text.Trim();
			_d90_ybb_glzx.sfmfy = Txtsfmfy.Text.Trim();
			_d90_ybb_glzx.sfmbc = Txtsfmbc.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_d90_ybb_glzx(_d90_ybb_glzx);
            else
                isok = mgr.Add_d90_ybb_glzx(_d90_ybb_glzx);
            if (isok)
            {
                d90_ybb_glzx_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("d90_ybb_glzx中执行了保存（插入或修改），并成功");
                d90_ybb_glzx_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}